const Koa = require('koa')
const app = new Koa()
const views = require('koa-views')
const InitManager = require('./core/init') // 引入路由

const bodyparser = require('koa-bodyparser')

const cors = require('@koa/cors');
 const catchError = require('./middlewares/exception')

app.use(bodyparser())
app.use(cors())


app.use(views(__dirname + '/views', {
  extension: 'pug'
}))
app.use(catchError)
InitManager.initCore(app)


// error-handling
app.on('error', (err, ctx) => {
  console.error('server error', err, ctx)
});
app.listen(3000, () => {
  console.log('Koa is listening in http://localhost:3000')
})

module.exports = app
